<template>
<div class="box">
    <el-card class="box-card">
        <template slot="header" >
            <img src="@/assets/logo.png" alt="">
        </template>
        <el-form :model="loginForm" :rules="rules" ref="rulesForm">
            <el-form-item prop="mobile">
                <el-input v-model.trim="loginForm.mobile" placeholder="请输入手机号"></el-input>
            </el-form-item>
            <el-form-item prop="code">
                <el-input v-model.trim="loginForm.code" placeholder="请输入验证码"></el-input>
            </el-form-item>
        </el-form>
        <el-checkbox>我已阅读并同意「用户协议」和「隐私条款」</el-checkbox>
        <el-button type="primary" @click="submit">登录</el-button>
    </el-card>
</div>
</template>

<script>
export default {
  name: 'login-page',
  components: {},
  props: {},
  data () {
    return {
      loginForm: {
        mobile: '13911111111',
        code: '246810'
      },
      rules: {
        mobile: [
          { required: true, message: '手机号为必填', trigger: 'blur' },
          { pattern: /^1\d{10}$/, message: '手机号码格式不正确', trigger: 'blur' }

        ],
        code: [
          { required: true, message: '验证码为必填项', trigger: 'blur' }
        ]
      }

    }
  },
  watch: {},
  computed: {},
  created () {

  },
  mounted () {},
  methods: {
    async submit () {
      try {
        // 表单二次校验
        await this.$refs.rulesForm.validate()
        await this.$store.dispatch('user/login', this.loginForm)
        this.$message.success('登录成功')
        this.$router.push('/dashboard')
      } catch (e) {
        console.log(e)
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.box{
    display: flex;
    justify-content: center;
    align-items: center;
  width: 100vw;
  height: 100vh;
  background: url('@/assets/login.png') no-repeat;
  background-size: revert;

}
.box-card {
    width: 480px;
  }
  ::v-deep .el-card__header{
    display: flex;
    justify-content: center;
  }
  .el-button{
    margin-top: 20px;
    width: 100%;
  }
  img{
    width: 200px;
    height: 60px;
  }
</style>
